var api = require('../../util/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function () {
        let chain = api.chain();
        this.setData({
            page: api.page(10),
            dataList: [],
            params : {
                examineId : chain.examineId,
                userId : chain.userId
            }
        });
        this.onReachBottom();
    },
    onPullDownRefresh(){
        this.setData({
            page: api.page(5),
            dataList: []
        });
        this.loadList();
    },
    onReachBottom() {
        this.loadList();
    },
    /**
     * 输入监听
     */
    searchInputAction: function (e) {
        let _this = this
        let value = e.detail.value
        if (value.length != 0) {
            _this.data.params['params[sql]'] = ` and (well_no like '%${value}%' 
                or unit like '%${value}%' 
                or team_no like '%${value}%' 
                or checker like '%${value}%' 
                or problem like '%${value}%')`
        }else{
            _this.data.params['params[sql]'] = ''
        }
        _this.setData({
            dataList : [],
            page: api.page(5)
        });
        _this.loadList();
    },
    loadList(){
        var _this = this;
        var params = _this.data.params;
        var page = _this.data.page;
        api.get(`${api.ip}lhjd/wtmxb/list`, params, page).then(res => {
            page.setTotal(res.total);
            if (res.rows.length == 0) {
                this.setData({
                    hasData: false
                })
            } else {
                _this.setData({
                    hasData: true,
                    dataList: _this.data.dataList.concat(res.rows)
                });
            }
        })
    },
    longPress(e) {
        var id = e.currentTarget.dataset.id;
        wx.showActionSheet({
            itemList: ['编辑'],
            success: function (res) {
                if (res.tapIndex == 0) {
                    wx.navigateTo({
                        url: `/pages/lhjd/wtmxb/edit?id=${id}`
                    });
                }
            },
            fail: function (res) {
                console.log(res.errMsg)
            }
        })
    },
    goAdd() {
        let chain = api.chain();
        let examineId = chain.examineId;
        let userId = chain.userId;
        let userName = chain.userName;
        wx.navigateTo({
          url: `./edit?examineId=${examineId}&userId=${userId}&userName=${userName}`
        });
      }
})